package dao;

import entity.*;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaQuery;
import vo.GradesVO;

/**
 *
 * @author Alexander
 */
public class GroupDAO implements IDAO {

    @Override
    public void persist(IEntity entity, EntityManager em) {
        em.persist(entity);
    }

    @Override
    public IEntity find(Object id, EntityManager em) {
        return (ClassGroup) em.find(ClassGroup.class, (String) id);
    }

    @Override
    public void update(IEntity entity, EntityManager em) {
        em.merge(entity);
    }

    @Override
    public void delete(Object id, EntityManager em) {
        ClassGroup grupo = em.getReference(ClassGroup.class, (String) id);
        em.remove(grupo);
    }

    @Override
    public List<IEntity> getList(EntityManager em) {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(ClassGroup.class));
        Query q = em.createQuery(cq);
        return q.getResultList();
    }

}
